﻿/**
 * DiscoveryHost Class - Created by FlashFrameLess 2008
 *
 * @author		FlashFrameLess - http://www.flashframeless.com/
 * @author		FabioTNT - http://www.fabiotnt.com/ - FlashFrameLess Team
 * @version		1.0
 */

package com.flashframeless.net {
	
	import flash.external.ExternalInterface;
	
	public class DiscoveryHost {
		
		private static var _hostUrl			: String;
		private static var _compilerHost	: String;
		private static var _mediaPath		: String;
		
		public function DiscoveryHost(){
			
			trace ( "DiscoveryHost is a static class and should not be instantiated." );
			
		}
		
		public static function getActualHost():String {
			
			if ( !_hostUrl ) {
				
				var url:String = ExternalInterface.call( "function(){return window.location.href;}" );
				
				if ( !url ){
					
					_hostUrl = _compilerHost;
					
				} else {
					
					if( url.lastIndexOf('/') < url.length && url.lastIndexOf('/') != -1 ){
						
						url = url.substr( 0, url.lastIndexOf('/') + 1 );
						
					}
					
					_hostUrl = url;
					
				}
				
			}
			
			return _hostUrl;
			
		}
		
		public static function set compilerHost( urlHost:String ) {
			
			_compilerHost = urlHost;
			
		}
		
		public static function get hostUrl():String {
			
			return _hostUrl;
			
		}
		
		public static function set mediaPath( path:String ) {
			
			_mediaPath = _hostUrl + path;
			
		}
		
		public static function get mediaPath():String {
			
			return _mediaPath;
			
		}
		
	}
	
}